// QuadPaint.cpp : implementation file
//

#include "stdafx.h"
#include "QuadIntrinsic.h"
#include "QuadPaint.h"
#include "QPContrlPanel.h"


// CQuadPaint dialog

IMPLEMENT_DYNAMIC(CQuadPaint, CDialog)

CQuadPaint::CQuadPaint(CWnd* pParent /*=NULL*/)
	: CDialog(CQuadPaint::IDD, pParent)	
{
	m_controlPanel = NULL;

}

CQuadPaint::~CQuadPaint()
{
}

void CQuadPaint::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_PIC_WINDOW, m_paintWnd);
}


BEGIN_MESSAGE_MAP(CQuadPaint, CDialog)
END_MESSAGE_MAP()

//added
void CQuadPaint::setImage(const Mat &img)
{
	assert(!img.empty());
	m_paintWnd.setImage(img);
}


// CQuadPaint message handlers

BOOL CQuadPaint::OnInitDialog()
{
	CDialog::OnInitDialog();

	// TODO:  Add extra initialization here

	//init paint wnd
	int w = m_paintWnd.m_orgImg.cols;
	int h = m_paintWnd.m_orgImg.rows;
	if (w > 1024 || h > 1024)
	{
		AfxMessageBox(_T("image size two large."), MB_OK);
		return FALSE;
	}
	MoveWindow(5, 5, w+10, h+10);
	m_paintWnd.MoveWindow(0, 0, w, h);

	//init control panel, paint wnd
	showControlPanel();
	m_paintWnd.setControlPanel(m_controlPanel);
	m_controlPanel->setPaintWnd(&m_paintWnd);
	if (m_controlPanel->isLocalBrush())
	{
		m_paintWnd.EnableLocalBrush();
	}

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}
void CQuadPaint::showControlPanel()
{
	if (m_controlPanel)
	{
		m_controlPanel->ShowWindow(SW_SHOW);
		m_controlPanel->SetForegroundWindow();
	}
	else
	{
		m_controlPanel = new CQPContrlPanel(this);
		m_controlPanel->Create(CQPContrlPanel::IDD, this);		
		m_controlPanel->ShowWindow(SW_SHOW);
	}

}


